package com.itheima.web.service.impl.ums;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.result.ResultData;
import com.itheima.service.ums.UmsResourceCategoryService;
import com.itheima.vo.ums.UmsResource;
import com.itheima.vo.ums.UmsResourceCategory;
import com.itheima.web.mapper.ums.UmsResourceCategoryMapper;
import com.itheima.web.mapper.ums.UmsResourceMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class UmsResourceCategoryServiceImpl extends ServiceImpl<UmsResourceCategoryMapper, UmsResourceCategory> implements UmsResourceCategoryService {
    @Autowired
    private UmsResourceCategoryMapper umsResourceCategoryMapper;
    @Autowired
    private UmsResourceMapper umsResourceMapper;

    @Override
    public ResultData delete(Integer id) {
        LambdaQueryWrapper<UmsResource> lqw=new LambdaQueryWrapper<>();
        lqw.eq(UmsResource::getCategoryId,id);
        List<UmsResource> umsResourceList = umsResourceMapper.selectList(lqw);
        if (umsResourceList!=null||umsResourceList.size()!=0){
            umsResourceCategoryMapper.deleteById(id);
            return ResultData.ok("操作成功","");
        }
        return ResultData.error("该分类下有资源,无法删除!");
    }
}
